//
//  CellOfBeLost.m
//  PetAPP
//
//  Created by dllo on 16/1/30.
//  Copyright © 2016年 Yuming. All rights reserved.
//

#import "CellOfBeLost.h"
#import "ModelOfBeLostDateList.h"
#import <YYWebImage.h>

@interface CellOfBeLost ()
/** 显示用户的头像 */
@property (nonatomic, retain) UIImageView *imageViewOfFace;
/** 毛的品种 */
@property (nonatomic, retain) UILabel *labelOfbreed;
/** 猫咪名字 */
@property (nonatomic, retain) UILabel *labelOfname;
/** 猫咪的年龄 */
@property (nonatomic, retain) UILabel *labelOfbirth;
/** 猫咪的性别 */
@property (nonatomic, retain) UIImageView *imageViewOfsex;
/** 丢失地点距离我有多远 */
@property (nonatomic, retain) UILabel *labelOfDistance;
/** 丢失时间 */
@property (nonatomic, retain) UILabel *labelOfLostTime;

@end


@implementation CellOfBeLost

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];

    }
    return self;
}


- (void)createSubViews {
    
    self.imageViewOfFace = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageViewOfFace];
    [_imageViewOfFace release];
    
    
    self.labelOfbreed = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOfbreed];
    [_labelOfbreed release];
    
    
    self.labelOfname = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOfname];
    [_labelOfname release];
    
    self.labelOfbirth = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOfbirth];
    [_labelOfbirth release];
    
    
    self.imageViewOfsex = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageViewOfsex];
    [_imageViewOfsex release];
    
    
    self.labelOfDistance = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOfDistance];
    [_labelOfDistance release];
    
    
    self.labelOfLostTime = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOfLostTime];
    [_labelOfLostTime release];
    

}

- (void)passContentWithModel:(ModelOfBeLostDateList *)model {
    
    self.imageViewOfFace.yy_imageURL = [NSURL URLWithString:model.pet_icon];
    
    self.labelOfbreed.text = model.pet_breed;
    
    self.labelOfname.text = model.pet_name;
    
    if ([model.pet_sex isEqualToString:@"1"]) {
        self.imageViewOfsex.image = [UIImage imageNamed:@"nv"];
    }else {
        self.imageViewOfsex.image = [UIImage imageNamed:@"nan"];
    }
    
    self.labelOfbirth.text = model.pet_birth;
    
    
    self.labelOfDistance.text = [NSString stringWithFormat:@"丢失地点距离你： %@", model.distance];
    
    self.labelOfLostTime.text = model.lost_time;
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    self.imageViewOfFace.frame = CGRectMake(15, 15, 70, 70);
    self.imageViewOfFace.layer.cornerRadius = 35;
    self.imageViewOfFace.layer.masksToBounds = YES;
    
    
    self.labelOfbreed.frame = CGRectMake(100, 15, 100, 25);
    self.labelOfbreed.font = [UIFont boldSystemFontOfSize:18];
    
     CGRect nameRect = [self.labelOfname.text boundingRectWithSize:CGSizeMake(0, 18) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil];
    
    self.labelOfname.frame = CGRectMake(100, 45, nameRect.size.width, 18);
    self.labelOfname.font = [UIFont systemFontOfSize:15];
    self.labelOfname.textColor = [UIColor grayColor];
    
    self.labelOfbirth.frame = CGRectMake(self.labelOfname.frame.size.width + self.labelOfname.frame.origin.x + 2, 45, 45, 18);
    self.labelOfbirth.textColor = [UIColor grayColor];
    self.labelOfbirth.font = [UIFont systemFontOfSize:15];
    
    
    
    
    self.imageViewOfsex.frame = CGRectMake(self.labelOfbirth.frame.size.width + self.labelOfbirth.frame.origin.x + 2, 43, 20, 20);
    
    self.labelOfDistance.frame = CGRectMake(100, 65, 300, 18);
    self.labelOfDistance.font = [UIFont systemFontOfSize:15];
    self.labelOfDistance.textColor = [UIColor grayColor];
    
    
    /** 设置丢失时间大小 */

    self.labelOfLostTime.font = [UIFont boldSystemFontOfSize:18];
    self.labelOfLostTime.textAlignment = NSTextAlignmentRight;
        self.labelOfLostTime.frame = CGRectMake(self.frame.size.width - 15 - 135, 15, 135, 25);
}



- (void)dealloc {
    [_imageViewOfFace release];
    [_labelOfbreed release];
    [_labelOfname release];
    [_labelOfbirth release];
    [_imageViewOfsex release];
    [_labelOfDistance release];
    [_labelOfLostTime release];
    [super dealloc];
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
